package com.ubaer.zsycz.ui.dialog;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.TextView;

import com.lsw.util.DensityUtil;
import com.lsw.view.ButtonTouch;
import com.ubaer.zsycz.R;

/**
 * Created by Administrator on 2018/9/25 0025.
 */

public class ConfirmDialog {
    public Dialog alertDialog;
    protected Context context;
    View view;
    ButtonTouch btnOk, btnCancel;
    TextView pub_tip, tv_content;


    public ConfirmDialog(Context context) {
        this.context = context;
        init();
    }

    @SuppressLint("InflateParams")
    @SuppressWarnings("deprecation")
    private void init() {
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflater.inflate(R.layout.dialog_confirm, null);
        view.setMinimumWidth(DensityUtil.dip2px(context, 300));
        btnOk = view.findViewById(R.id.btnOk);
        btnCancel = view.findViewById(R.id.btnCancel);
        pub_tip = view.findViewById(R.id.pub_tip);
        tv_content = view.findViewById(R.id.tv_content);
        alertDialog = new Dialog(context, R.style.dialogStyle);
        alertDialog.setContentView(view);
//        alertDialog.setCancelable(false);
        Window dialogWindow = alertDialog.getWindow();
        dialogWindow.setGravity(Gravity.CENTER);
        btnCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
    }

    public void show(View.OnClickListener onClickListener) {
        pub_tip.setText("提订单充值确认");
        tv_content.setText("确认所选订单全部为充值成功订单吗？（如有充值失败订单，请单独处理）。");
        if (onClickListener != null) {
            btnOk.setOnClickListener(onClickListener);
        }
        if (!alertDialog.isShowing()) {
            alertDialog.show();
        }
    }

    public void showLoginout(View.OnClickListener onClickListener) {
        pub_tip.setText("提示");
        tv_content.setText("确认要退出登录？");
        if (onClickListener != null) {
            btnOk.setOnClickListener(onClickListener);
        }
        if (!alertDialog.isShowing()) {
            alertDialog.show();
        }
    }

    public void dismiss() {
        if (alertDialog.isShowing()) {
            alertDialog.dismiss();
        }
    }
}
